﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/calendar/module.master" %>
<%@ Register Src="~/ColorworksDataSources.ascx" TagName="ColorworksDataSources" TagPrefix="myds" %>
<%@ Register Assembly="DevExpress.XtraScheduler.v9.2.Core, Version=9.2.6.0" Namespace="DevExpress.XtraScheduler" TagPrefix="cc1" %>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        string n = Request.QueryString["h"] ?? "500";
        int h = int.Parse(n) - 100;
        ASPxScheduler1.DayView.Styles.ScrollAreaHeight = h;

        DevExpress.Web.ASPxClasses.ASPxWebControl.RegisterBaseScript(Page);
        DataHelper.SetupDefaultMappings(ASPxScheduler1);
        DataHelper.ProvideRowInsertion(ASPxScheduler1, schedulerDataSource.AppointmentDataSource);
        schedulerDataSource.AttachTo(ASPxScheduler1);

        ApplyDateNavigatorProperties();
    }

    void ApplyDateNavigatorProperties()
    {
        DateNavigatorProperties props = ASPxDateNavigator1.Properties;
        props.BoldAppointmentDates = true;
        props.ShowTodayButton = true;
        props.ShowWeekNumbers = true;

        ASPxScheduler1.ApplyChanges(ASPxSchedulerChangeAction.NotifyVisibleIntervalsChanged);
    }

    protected void OnSchedulerBeforeExecuteCallbackCommand(object sender, DevExpress.Web.ASPxScheduler.SchedulerCallbackCommandEventArgs e)
    {
        if (e.CommandId == "EnableToolTipCallback")
        {
            //  e.Command = new EnableToolTipCallback(ASPxScheduler1);
        }
    }

    protected void CellPrepared(object sender, DevExpress.Web.ASPxScheduler.ASPxSchedulerTimeCellPreparedEventArgs e)
    {
        e.Cell.BackColor = System.Drawing.Color.White;
        e.Cell.BorderColor = System.Drawing.Color.Gray;
        e.Cell.BorderWidth = 1;
        
    }
    
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" src="/jquery.min.js"></script>
    <script type="text/javascript">
        var _load = false;
        var _resize = false;

        $(document).ready(function () {

            var h = $(window).height();
            var w = $(window).width();
            //$("#userbar").css('height', h - 72);
            //$("#framebar").css('height', h - 73);
            //$("#appbar").css('width', w - 208);

            //$(window).resize(function () {
            //    var h = $(window).height();
            //    var w = $(window).width();
            //    $("#userbar").css('height', h - 72);
            //    $("#framebar").css('height', h - 73);
            //    $("#appbar").css('width', w - 208);
            //});


        });



        function OpenAppointment(scheduler) {
            var apt = GetSelectedAppointment(scheduler);
            scheduler.RefreshClientAppointmentProperties(apt, AppointmentPropertyNames.Normal, OnAppointmentRefresh);
        }
        function EditSeries(scheduler) {
            var apt = GetSelectedAppointment(scheduler);
            scheduler.RefreshClientAppointmentProperties(apt, AppointmentPropertyNames.Pattern, OnAppointmentEditSeriesRefresh);
        }
        function OnAppointmentRefresh(apt) {
            ShowAppointmentForm(apt);
        }
        function OnAppointmentEditSeriesRefresh(apt) {
            if (apt.GetRecurrencePattern()) {
                ShowAppointmentForm(apt.GetRecurrencePattern());
            }
        }
        function NewAppointment(scheduler) {
            var apt = CreateAppointment(scheduler)
            ShowAppointmentForm(apt);
        }
        function NewRecurringAppointment(scheduler) {
            var apt = CreateRecurringAppointment(scheduler);
            ShowAppointmentForm(apt);
        }
        function NewRecurringEvent(scheduler) {
            var apt = CreateRecurringEvent(scheduler);
            ShowAppointmentForm(apt);
        }
        function NewAllDayEvent(scheduler) {
            var apt = CreateAllDayEvent(scheduler);
            ShowAppointmentForm(apt);
        }
        function ShowAppointmentForm(apt) {
            scheduler.HideLoadingPanel();
            MyScriptForm.Clear();
            MyScriptForm.Update(apt);
            if (apt.GetSubject() != "")
                myFormPopup.SetHeaderText(apt.GetSubject() + " - Appointment");
            else
                myFormPopup.SetHeaderText("Untitled - Appointment");
            myFormPopup.Show();
        }
        function CloseAppointmentForm() {
            myFormPopup.Hide();
        }
        function CreateAppointment(scheduler) {
            var apt = new ASPxClientAppointment();
            var selectedInterval = scheduler.GetSelectedInterval();
            apt.SetStart(selectedInterval.GetStart());
            apt.SetEnd(selectedInterval.GetEnd());
            apt.AddResource(scheduler.GetSelectedResource());
            apt.SetLabelId(0);
            apt.SetStatusId(0);
            return apt;
        }
        function CreateRecurringAppointment(scheduler) {
            var apt = CreateAppointment(scheduler);
            apt.SetAppointmentType(ASPxAppointmentType.Pattern);
            var recurrenceInfo = new ASPxClientRecurrenceInfo();
            recurrenceInfo.SetStart(apt.GetStart());
            recurrenceInfo.SetEnd(apt.GetEnd());
            apt.SetRecurrenceInfo(recurrenceInfo);
            return apt;
        }
        function CreateAllDayEvent(scheduler) {
            var apt = CreateAppointment(scheduler);
            var start = apt.interval.start;
            var today = new Date(start.getFullYear(), start.getMonth(), start.getDate());
            apt.SetStart(today);
            apt.SetDuration(24 * 60 * 60 * 1000);
            apt.SetAllDay(true);
            return apt;
        }
        function CreateRecurringEvent(scheduler) {
            var apt = CreateAllDayEvent(scheduler);
            apt.SetAppointmentType(ASPxAppointmentType.Pattern);
            var recurrenceInfo = new ASPxClientRecurrenceInfo();
            recurrenceInfo.SetStart(apt.GetStart());
            recurrenceInfo.SetEnd(apt.GetEnd());
            apt.SetRecurrenceInfo(recurrenceInfo);
            return apt;
        }
        function GetSelectedAppointment(scheduler) {
            var aptIds = scheduler.GetSelectedAppointmentIds();
            if (aptIds.length == 0)
                return;
            var apt = scheduler.GetAppointmentById(aptIds[0]);
            return apt;
        }
    </script>
    <script type="text/javascript">
        var globalMouseX = 0;
        var globalMouseY = 0;
        var detectedMouseUp = false;
        var detectedSelectionChanged = false
        ASPxClientUtils.AttachEventToElement(document, "mousemove", createEventHandler("OnMouseMove"));
        ASPxClientUtils.AttachEventToElement(document, "mouseup", createEventHandler("OnMouseUp"));
        function OnMouseMove(evt) {
            globalMouseX = ASPxClientUtils.GetEventX(evt);
            globalMouseY = ASPxClientUtils.GetEventY(evt);
            detectedSelectionChanged = false;
            detectedMouseUp = false;
        }
        function OnMouseUp(evt) {
            detectedMouseUp = true;
            ShowToolTip();
        }
        function createEventHandler(funcName) {
            return new Function("event", funcName + "(event);");
        }
        function OnSelectionChanged(s, e) {
            if (!scheduler.isAllowEvent)
                return;
            detectedSelectionChanged = true;
            ShowToolTip();
        }
        function ShowToolTip() {
            if (detectedSelectionChanged && detectedMouseUp) {
                scheduler.ShowSelectionToolTip(globalMouseX, globalMouseY);
                detectedSelectionChanged = false;
                detectedMouseUp = false;
            }
        }
        function OnBeginCallback() {
            delete scheduler.isAllowEvent;
        }
        function OnEndCallback() {
            scheduler.isAllowEvent = true;
        }
        function OnControlInitialized() {
            scheduler.isAllowEvent = true;
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

	<myds:ColorworksDataSources runat="server" ID="schedulerDataSource" />
    
     <table border=0 cellpadding=0 cellspacing=0 width="100%" height="100%">
    <tr>

      <td width="150" valign="top">

      <dxwschs:ASPxDateNavigator runat="server" ID="ASPxDateNavigator1" MasterControlID="ASPxScheduler1" Width="120px">
            <Properties Rows="1" DayNameFormat="FirstLetter"  DayHeaderStyle-Font-Size ="10px" DayStyle-Font-Size="10px"  />
                       
        </dxwschs:ASPxDateNavigator>
    
    <br />

    <dxe:ASPxRadioButtonList ID="rbVisibility" runat="server" ValueType="System.Int32" SelectedIndex="2" RepeatDirection="Vertical" TextWrap="False" Width="100%" ItemSpacing="10px" EnableClientSideAPI="True">
						<Border BorderStyle="None" />
						<Items>
							<dxe:ListEditItem Text="Normal Display" Value="0" />
							<dxe:ListEditItem Text="By Date/Technician" Value="1" />
							<dxe:ListEditItem Text="By Technician/Date" Value="2" />
						</Items>
						<Paddings Padding="0px" />
						<ClientSideEvents SelectedIndexChanged="function(s, e) {
							switch(s.savedSelectedIndex) {
								case 0:
									scheduler.SetGroupType(ASPxSchedulerGroupType.None);
									break;
								case 1:
									scheduler.SetGroupType(ASPxSchedulerGroupType.Date);
									break;
								case 2:
									scheduler.SetGroupType(ASPxSchedulerGroupType.Resource);
									break;
								}
									}" />
					</dxe:ASPxRadioButtonList>
                    <br />
                    <br />
                    &nbsp;&nbsp;<a href="javascript:scheduler.ShowLoadingPanel();NewAppointment(scheduler);">All Appointment</a>
    </td>


    <td width="*" valign="top">
    <dxwschs:ASPxScheduler id="ASPxScheduler1" GroupType="Resource" 
    ResourceNavigator-Visibility ="Never" runat="server" Width="100%" 
    ClientInstanceName="scheduler"  OnHtmlTimeCellPrepared="CellPrepared" OnBeforeExecuteCallbackCommand="OnSchedulerBeforeExecuteCallbackCommand">
        
        <ClientSideEvents
           SelectionChanged="function(s,e) { OnSelectionChanged(s, e); }"
           BeginCallback="function(s,e) { OnBeginCallback(s, e); }"
           EndCallback="function(s,e) {OnEndCallback(s,e); }"
         />
        <Storage EnableReminders="False">
<Appointments ResourceSharing="true"><CustomFieldMappings>
<dxwschs:ASPxAppointmentCustomFieldMapping Member="Price" Name="Price"></dxwschs:ASPxAppointmentCustomFieldMapping>
<dxwschs:ASPxAppointmentCustomFieldMapping Member="ContactInfo" Name="ContactInfo"></dxwschs:ASPxAppointmentCustomFieldMapping>
</CustomFieldMappings>
</Appointments>
</Storage>

<Views>
             <DayView>
                 <TimeRulers><cc1:TimeRuler /></TimeRulers>
                 <DayViewStyles ScrollAreaHeight="500px"  AllDayArea-Font-Size="10px" AllDayArea-BackColor="White" />
             </DayView>
             <WorkWeekView>
                 <TimeRulers><cc1:TimeRuler /></TimeRulers>
                 <WorkWeekViewStyles ScrollAreaHeight="500px" />
             </WorkWeekView>
             <WeekView>
               <WeekViewStyles>
                 <DateCellBody Height="200px" />                
               </WeekViewStyles>
             </WeekView>
             <MonthView>
               <MonthViewStyles>
                 <DateCellBody Height="100px" />                
               </MonthViewStyles>
             </MonthView>
             <TimelineView>
               <TimelineViewStyles>
                 <TimelineCellBody Height="500px" />                
               </TimelineViewStyles>
             </TimelineView>
         </Views>

    </dxwschs:ASPxScheduler>
   
    
    </td>
  
    </tr>
    
    </table>




</asp:Content>

